<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div {
            width: 600px;
            height: 100px;
            overflow: auto;
            position: absolute;
        }

        table {
            height: 100px;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid #000;
            padding: 10px;
        }

        th {
            position: sticky;
            background-color: #cccccc;
            top: 0;
        }
    </style>
</head>
<body>
<div>
    <table>
        <thead>
        <tr>
            <th>序号</th>
            <th>名称</th>
            <th>年龄</th>
            <th>性别</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>1</td>
            <td>张三</td>
            <td>18</td>
            <td>男</td>
        </tr>
        <tr>
            <td>2</td>
            <td>李四</td>
            <td>19</td>
            <td>男</td>
        </tr>
        <tr>
            <td>3</td>
            <td>王五</td>
            <td>20</td>
            <td>男</td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>